/**
 * Copyright (C) 2012-2013 jumei, Inc.
 * ServiceHandlerAdaptor.java
 * 2015年6月26日
 */
package org.goface.rpc.pipeline;

import org.goface.rpc.MessageContext;

/**
 * TODO Please Descrip This Class
 *
 * @author jm110
 */
public abstract class ServiceHandlerAdaptor implements ServiceHandler {

    /*
     * (non-Javadoc)
     *
     * @see org.goface.rpc.pipeline.ServiceHandler#sendRequest(org.goface.rpc.pipeline.ServiceHandlerContext,
     * org.goface.rpc.MessageContext)
     */
    @Override
    public void sendRequest(ServiceHandlerContext context, MessageContext message) throws Throwable {
        ServiceHandlerContext next = context.getNext();
        if (next != null) {
            next.getHandler().sendRequest(next, message);
        }
    }

    /*
     * (non-Javadoc)
     *
     * @see org.goface.rpc.pipeline.ServiceHandler#sendResponse(org.goface.rpc.pipeline.ServiceHandlerContext,
     * org.goface.rpc.MessageContext)
     */
    @Override
    public void sendResponse(ServiceHandlerContext context, MessageContext message) throws Throwable {
        ServiceHandlerContext next = context.getNext();
        if (next != null) {
            next.getHandler().sendRequest(next, message);
        }

    }

    /*
     * (non-Javadoc)
     *
     * @see org.goface.rpc.pipeline.ServiceHandler#receiveRequest(org.goface.rpc.pipeline.ServiceHandlerContext,
     * org.goface.rpc.MessageContext)
     */
    @Override
    public void receiveRequest(ServiceHandlerContext context, MessageContext message) throws Throwable {
        ServiceHandlerContext pre = context.getPreviouse();
        if (pre != null) {
            pre.getHandler().sendRequest(pre, message);
        }

    }

    /*
     * (non-Javadoc)
     *
     * @see org.goface.rpc.pipeline.ServiceHandler#receiveResponse(org.goface.rpc.pipeline.ServiceHandlerContext,
     * org.goface.rpc.MessageContext)
     */
    @Override
    public void receiveResponse(ServiceHandlerContext context, MessageContext message) throws Throwable {
        ServiceHandlerContext pre = context.getPreviouse();
        if (pre != null) {
            pre.getHandler().receiveResponse(pre, message);
        }

    }

    /*
     * (non-Javadoc)
     *
     * @see org.goface.rpc.pipeline.ServiceHandler#onException(org.goface.rpc.pipeline.ServiceHandlerContext,
     * org.goface.rpc.MessageContext)
     */
    @Override
    public void onException(ServiceHandlerContext context, MessageContext messageContext)  {

      if(  messageContext.isRequestMessage()){
                //TODO 按照消息类别处理异常
      }
    }

}
